/**
 * jims
 */
package com.jims.master.modules.oper.service;

import com.jims.master.common.persistence.Page;
import com.jims.master.common.service.TreeService;
import com.jims.master.modules.oper.dao.ExamTypeDao;
import com.jims.master.modules.oper.entity.ClinicItemDict;
import com.jims.master.modules.oper.entity.ExamType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Service
 * @author 赵宁
 * @version 2017-02-23
 */
@Service
@Transactional(readOnly = true)
public class ExamTypeService extends TreeService<ExamTypeDao, ExamType> {
    @Autowired
    private ExamTypeDao examTypeDao;

	public ExamType get(String id) {
		return super.get(id);
	}
	
	public List<ExamType> findList(ExamType examType) {
		return super.findList(examType);
	}
	
	public Page<ExamType> findPage(Page<ExamType> page, ExamType examType) {
		return super.findPage(page, examType);
	}

	public Page<ExamType> findPageParentIdsLike(Page<ExamType> page, ExamType examType) {
		examType.updateOrgId();
		examType.setPage(page);
		page.setList(dao.findByParentIdsLike(examType));
		return page;
	}

	/**
	 * 保存检查类型
	 * @param examType
	 * @return
	 * @author 赵宁
	 */
	@Transactional(readOnly = false)
	public int save(ExamType examType) {
		if(examType.getParent()!=null&& !"".equals(examType.getParent().getId())&& !"0".equals(examType.getParent().getId())){
			 examType.setLevel("2");
		}else{
			examType.setLevel("1");
		}
		return super.save(examType);
	}
	
	@Transactional(readOnly = false)
	public int delete(ExamType examType) {
		return super.delete(examType);
	}

    /**
     * 根据上级检查项目查询下级检查项目
     * @param pId
     * @return
     * @Author 陈晓阳
     */
    public List<ExamType> findByPId(String pId) {
        return this.examTypeDao.findByPId(pId);
    }

    /**
     * 根据检查项目查询诊疗项目与执行科室
     * @param examId    检查项目Id
     * @return
     * @Author 陈晓阳
     */
    public List<ClinicItemDict> findByExam(String examId) {
        return this.examTypeDao.findByExam(examId);
    }

	public ExamType getPerformedBy(String id){
		ExamType examType = examTypeDao.getPerformedBy(id);
		return examType;
	}
}